package simtester.server



import grails.test.mixin.*
import org.junit.*

/**
 * See the API for {@link grails.test.mixin.web.ControllerUnitTestMixin} for usage instructions
 */
@TestFor(TestSuiteController)
@Mock([User,TestCase,TestSuite,Team])
class TestSuiteControllerTests {

    @Test
    void createTestSuite() {
        def testuserName = 'user'
        def testteamName = 'svt'
        def testsuiteName = 'My Suite'
        def testcaseNames = ['mytest1', 'test 2']
       
        def user = new User(username: testuserName, password: 'pass')
        def team = new Team(name: testteamName)
        team.addToUsers(user)
        team.save(failOnError:true)
       
        def testcases = []
        testcaseNames.each {
            def tc = new TestCase(name: it, script: 'some script', owner: user)
            team.addToTestcases(tc)
            testcases << tc
        }
        team.save(failOnError:true)
       
        session.user = testuserName
        params.testcase = testcases.collect { it.id.toString() }
        params.type = 'Load'
        params.name = testsuiteName
        controller.create()
        
        assert response.redirectedUrl == '/testSuite/list'
        
        def newSuite = TestSuite.findByName('My Suite')
        assert newSuite.name == testsuiteName
        assert newSuite.owner.username == testuserName
        assert newSuite.team.name  == testteamName
        
        def tests = newSuite.testcases
        assert tests.size() == 2
    }
}
